package com.letoken.platform.repo.app.manager;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.letoken.platform.pub.constant.AdminMenuConstant;
import com.letoken.platform.repo.admin.dao.AdminMenuMapper;
import com.letoken.platform.repo.admin.po.AdminMenu;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wyl
 * @date 2023/3/30 16:27
 * @Version 1.0
 */
@Log4j2
@Repository
public class AdminMenuManager {
    @Autowired
    private AdminMenuMapper adminMenuMapper;

    @Autowired
    private AdminRoleMenuManager adminRoleMenuManager;

    public List<Integer> deleteMenuByPidList(List<Integer> pidList) {
        LambdaQueryWrapper<AdminMenu> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper
                .in(AdminMenu::getPid, pidList);
        List<AdminMenu> adminMenuList = adminMenuMapper.selectList(queryWrapper);
        List<Integer> collect = adminMenuList.stream().map(AdminMenu::getAdminMenuId).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)) {
            adminMenuMapper.deleteBatchIds(collect);
            adminRoleMenuManager.delByMenuId(collect);
        }
        if (CollUtil.isEmpty(adminMenuList)) {
            return null;
        }
        return collect;
    }

}
